package com.xyzk.diagnose.activity.adapter;

import com.xyzk.diagnose.R;
import com.xyzk.diagnose.TApplication;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SettingMenuAdapter extends BaseAdapter{
	private String [] datas;
	private int [] resIds;
	private int selectId;

	/**
	 * @param datas  数据资源
	 * @param resIds 图片资源id
	 */
	public SettingMenuAdapter(String [] datas,int [] resIds) {
		this.datas = datas;
		this.resIds = resIds;
	}

	@Override
	public int getCount() {
		return datas == null ? 0 : datas.length;

	}

	@Override
	public Object getItem(int position) {
		return datas == null ? 0 : datas[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	/**
	 * 选中菜单
	 * @param pos 下标
	 */
	public void setSelected(int pos){
		selectId = pos;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		ViewHolder vh;
		if(view == null){
			view = View.inflate(TApplication.getContext(), R.layout.activity_setting_menu_item,null);
			vh = new ViewHolder();
			vh.textView = (TextView) view.findViewById(R.id.tv_setting_item);
			vh.imageView = (ImageView) view.findViewById(R.id.iv_setting_item);
			view.setTag(vh);
		}else{
			vh = (ViewHolder) view.getTag();
		}
		if(selectId == position){
			view.setBackgroundColor(0xFFC0C0FF);
		}else{
			view.setBackgroundColor(0xFFEEEEEE);
		}
		vh.textView.setText(datas[position]);
		vh.imageView.setImageResource(resIds[position]);
		return view;
	}

	class ViewHolder{
		TextView textView;
		ImageView imageView;
	}
}
